<?php echo $header; ?>
<div id="content">
    <div class="breadcrumb">
        <?php foreach ($breadcrumbs as $breadcrumb) { ?>
        <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
        <?php } ?>
    </div>
    <?php if ($error_warning) { ?>
    <div class="warning"><?php echo $error_warning; ?></div>
    <?php } ?>
    <div class="box">
        <div class="heading">
            <h1><img src="view/image/information.png" alt="" /> 套餐管理</h1>
            <div class="buttons"><a onclick="$('#form').submit();" class="button">保存</a>
                <a onclick="location = '<?php echo $cancel; ?>';" class="button">取消</a></div>        </div>
        <div class="content">
            <form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form">
                <table class="form">
                    <tr>
                        <td><span class="required">*</span> 套餐名</td>
                        <td><input type="text" name="name" value="<?php echo $name; ?>" size="20" />
                            <?php if ($error_name) { ?>
                            <span class="error"><?php echo $error_name; ?></span>
                            <?php } ?></td>
                    </tr>
                    <tr>
                        <td>套餐描述</td>
                        <td>
                            <textarea name="description" rows="10" cols="50"><?php echo $description; ?></textarea>
                            <?php if ($error_name) { ?>
                            <span class="error"><?php echo $error_name; ?></span>
                            <?php } ?></td>                    </tr>
                </table>
                <table id="option-value" class="list">
                    <thead>
                    <tr>
                        <td class="left"><span class="required">*</span>套餐名</td>
                        <td class="left">套餐月费</td>
                        <td class="left">返还金额</td>
                        <td class="left">赠送金额</td>
                        <td class="left">合约期</td>
                        <td></td>
                    </tr>
                    </thead>
                    <?php $option_value_row = 0; ?>
                    <?php foreach ($option_values as $option_value) { ?>
                    <tbody id="option-value-row<?php echo $option_value_row; ?>">
                    <tr>
                        <td class="left"><input type="text" name="option_value[<?php echo $option_value_row; ?>][name]" value="<?php echo $option_value['name']; ?>"  /></td>
                        <td class="left"><input type="text" name="option_value[<?php echo $option_value_row; ?>][month_price]" value="<?php echo $option_value['month_price']; ?>"  /></td>
                        <td class="left"><input type="text" name="option_value[<?php echo $option_value_row; ?>][return_money]" value="<?php echo $option_value['return_money']; ?>"  /></td>
                        <td class="left"><input type="text" name="option_value[<?php echo $option_value_row; ?>][give_money]" value="<?php echo $option_value['give_money']; ?>"  /></td>
                        <td class="left"><input type="text" name="option_value[<?php echo $option_value_row; ?>][time]" value="<?php echo $option_value['time']; ?>"  /></td>
                        <td class="left"><a onclick="$('#option-value-row<?php echo $option_value_row; ?>').remove();" class="button">移除</a></td>
                    </tr>
                    </tbody>
                    <?php $option_value_row++; ?>
                    <?php } ?>
                    <tfoot>
                    <tr>
                        <td colspan="5"></td>
                        <td class="left"><a onclick="addOptionValue();" class="button">添加套餐</a></td>
                    </tr>
                    </tfoot>
                </table>
            </form>
        </div>
    </div>
</div>
<script type="text/javascript"><!--
$('select[name=\'type\']').bind('change', function() {
    if (this.value == 'select' || this.value == 'radio' || this.value == 'checkbox' || this.value == 'image') {
        $('#option-value').show();
    } else {
        $('#option-value').hide();
    }
});

var option_value_row = <?php echo $option_value_row; ?>;

function addOptionValue() {
    html  = '<tbody id="option-value-row' + option_value_row + '">';
    html += '<tr>';
    html += '<td class="left"><input type="text" name="option_value[' + option_value_row + '][name]" value=""  /></td>';
    html += '<td class="left"><input type="text" name="option_value[' + option_value_row + '][month_price]" value="" /></td>';
    html += '<td class="left"><input type="text" name="option_value[' + option_value_row + '][return_money]" value="" /></td>';
    html += '<td class="left"><input type="text" name="option_value[' + option_value_row + '][give_money]" value="" /></td>';
    html += '<td class="left"><input type="text" name="option_value[' + option_value_row + '][time]" value="" /></td>';
    html += '<td class="left"><a onclick="$(\'#option-value-row' + option_value_row + '\').remove();" class="button">移除</a></td>';
    html += '</tr>';
    html += '</tbody>';

    $('#option-value tfoot').before(html);

    option_value_row++;
}
//--></script>
<script type="text/javascript"><!--
function image_upload(field, thumb) {
    $('#dialog').remove();

    $('#content').prepend('<div id="dialog" style="padding: 3px 0px 0px 0px;"><iframe src="index.php?route=common/filemanager&token=<?php echo $token; ?>&field=' + encodeURIComponent(field) + '" style="padding:0; margin: 0; display: block; width: 100%; height: 100%;" frameborder="no" scrolling="auto"></iframe></div>');

    $('#dialog').dialog({
        title: '<?php echo $text_image_manager; ?>',
        close: function (event, ui) {
            if ($('#' + field).attr('value')) {
                $.ajax({
                    url: 'index.php?route=common/filemanager/image&token=<?php echo $token; ?>&image=' + encodeURIComponent($('#' + field).attr('value')),
                    dataType: 'text',
                    success: function(data) {
                        $('#' + thumb).replaceWith('<img src="' + data + '" alt="" id="' + thumb + '" />');
                    }
                });
            }
        },
        bgiframe: false,
        width: 800,
        height: 400,
        resizable: false,
        modal: false
    });
};
//--></script>
<?php echo $footer; ?>